<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象的创建汇总</title>
</head>
<body>
<script type="text/javascript">

    // Object 构造函数模式
    var p = new Object(); // = var p={}
    p.name = 'Tom'
    p.setName = function(name){
        this.name = name
    }

    // 对象字面量
    var obj = {
        name:name,
        setName:function(name){
            this.name = name
        }
    }

    // 构造函数模式
    function Person(name,age){
        this.name = name
        this.age = age
        this.setName = function(name){
            this.name = name
        }
    }
    var p = new Person('Tom',12)

    // 构造函数 ＋ 原型的组合模式
    function Person(name,age){
        this.name = name
        this.age = age
    }
    Person.prototype.setName = function(name){
        this.name = name
    }
    var p = new Person('Tom',12)
</script>
</body>
</html>